//
//  VC_Audio.m
//  yjw-winner
//
//  Created by Kae on 2018/9/5.
//  Copyright © 2018年 Shanghai decade financial information service co., LTD. All rights reserved.
//

#import "VC_Audio.h"
#import "AudioPlayerManager.h"
#import "Cell_AudioList.h"

static NSString *identifier = @"audio_list_cell_identifier";
@interface VC_Audio ()<UITableViewDelegate, UITableViewDataSource> {
    AudioPlayerManager *_manager;
    UITableView *_tableView;
    CGRect _playerFrame;
    CGRect _headerFrame;
}
@property (nonatomic, strong) NSArray *dataArray;
@end

@implementation VC_Audio
- (NSArray *)dataArray {
    if (!_dataArray) {
        _dataArray = @[@"",
                       @"",
                       @"",
                       @"",
                       @""];
    }
    return _dataArray;
}
- (void)viewDidLoad {
    [super viewDidLoad];
    self.view.backgroundColor = [UIColor whiteColor];
    [self initPlayer];
    [self initTableViewHeader];
    [self initTableView];
}

- (void)initPlayer {
    _manager = [AudioPlayerManager manager];
    View_AudioPlayer *playerView = _manager.playerView;
    playerView.frame = CGRectMake(0, 0, self.view.mj_w, 364);
    _playerFrame = playerView.frame;
    [self.view addSubview:playerView];
}
- (void)initTableViewHeader {
    UIView *v = [[UIView alloc] initWithFrame:CGRectMake(0, _playerFrame.origin.y + _playerFrame.size.height, self.view.mj_w, 56)];
    v.backgroundColor = [UIColor whiteColor];
    [self.view addSubview:v];
    _headerFrame = v.frame;
    UILabel *l = [[UILabel alloc] initWithFrame:CGRectMake(10, 0, 100, v.mj_h)];
    l.font = [UIFont systemFontOfSize:14.0f];
    l.text = @"播放列表";
    [v addSubview:l];
    
    // 添加缓存全部 button
    
}
- (void)initTableView {
    _tableView = [[UITableView alloc] initWithFrame:CGRectMake(10, _headerFrame.origin.y + _headerFrame.size.height, self.view.mj_w - 20, self.view.bounds.size.height - _headerFrame.origin.y - _headerFrame.size.height) style:UITableViewStylePlain];
    _tableView.showsVerticalScrollIndicator = NO;
    _tableView.showsHorizontalScrollIndicator = NO;
    _tableView.tableFooterView = [UIView new];
    _tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
    _tableView.delegate = self;
    _tableView.dataSource = self;
    [self.view addSubview:_tableView];
    [_tableView registerNib:[UINib nibWithNibName:NSStringFromClass([Cell_AudioList class]) bundle:[NSBundle mainBundle]] forCellReuseIdentifier:identifier];
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    Cell_AudioList *cell = [tableView dequeueReusableCellWithIdentifier:identifier forIndexPath:indexPath];
    if (!cell) {
        cell = [[Cell_AudioList alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:identifier];
    }
    return cell;
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
    return 44.0f;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return self.dataArray.count;
}
@end
